package de.koller.million.grid.frame.ply;

import de.koller.million.grid.GNode;
import de.koller.million.grid.commands.RemoveGNode;
import de.koller.million.grid.engine.player.Player;

public class PlayerFrame extends GNode {

	private final PlayerFrameComp comp;
	public final Player player;
	
	public PlayerFrame( Player player ) {
		this.player = player;
		comp = new PlayerFrameComp( this );
	}
	
	@Override
	protected void init() {
		super.init();
		
		comp.setVisible( true );
		comp.setTitle( "Spieler [" + player.name + "]" );
	}

	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		comp.hp.repaint();
		comp.showEnc.setEnabled( player.getEncounter() != null );
		
		comp.valLife.setText( (int)player.playerStats.healthPoints.getValue() + "" );
		comp.valFood.setText( (int)player.playerStats.foodGen.getValue() + "" );
		comp.valDamage.setText( (int)player.playerStats.damage.getValue() + "" );
		comp.valSpeed.setText( player.playerStats.speed.getValue() + "" );
	}
	
	@Override
	protected void release() {
		super.release();
		
		comp.dispose();
	}
	
	public void closeThis() {
		groot.call( new RemoveGNode( this ) );
	}
	
}
